package cn.seocoo.platform.web.controller.report;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import cn.seocoo.platform.common.annotation.Log;
import cn.seocoo.platform.common.enums.BusinessType;
import cn.seocoo.platform.report.domain.Report;
import cn.seocoo.platform.report.service.IReportService;
import cn.seocoo.platform.common.core.controller.BaseController;
import cn.seocoo.platform.common.core.page.TableDataInfo;
import cn.seocoo.platform.common.core.domain.AjaxResult;
import cn.seocoo.platform.common.utils.poi.ExcelUtil;

/**
 * 举报 信息操作处理
 * 
 * @author wujian
 * @date 2019-12-23
 */
@Controller
@RequestMapping("/report/report")
public class ReportController extends BaseController
{
    private String prefix = "report/report";
	
	@Autowired
	private IReportService reportService;
	
	@RequiresPermissions("report:report:view")
	@GetMapping()
	public String report()
	{
	    return prefix + "/report";
	}
	
	/**
	 * 查询举报列表
	 */
	@RequiresPermissions("report:report:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Report report)
	{
		startPage();
        List<Report> list = reportService.selectReportList(report);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出举报列表
	 */
	@RequiresPermissions("report:report:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Report report)
    {
    	List<Report> list = reportService.selectReportList(report);
        ExcelUtil<Report> util = new ExcelUtil<Report>(Report.class);
        return util.exportExcel(list, "report");
    }
	
	/**
	 * 新增举报
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存举报
	 */
	@RequiresPermissions("report:report:add")
	@Log(title = "举报", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Report report)
	{		
		return toAjax(reportService.insertReport(report));
	}

	/**
	 * 修改举报
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap)
	{
		Report report = reportService.selectReportById(id);
		mmap.put("report", report);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存举报
	 */
	@RequiresPermissions("report:report:edit")
	@Log(title = "举报", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Report report)
	{		
		return toAjax(reportService.updateReport(report));
	}
	
	/**
	 * 删除举报
	 */
	@RequiresPermissions("report:report:remove")
	@Log(title = "举报", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(reportService.deleteReportByIds(ids));
	}
	
}
